# _*_ coding=utf-8 _*_
# file:MakeMode.py

import os
import sys
import string
import datetime

# python 脚本模板
py='''#------------------------------------------------
# TO:
#------------------------------------------------
# BY: Yongtao Zhou
#------------------------------------------------
'''
if os.path.isfile(sys.argv[1]):#sys.argv[1] 表示命令行参数中的第二位，如python MakeCode.py test.py中的‘test.py’,'MakeCode.py'为sys.argv[0]
    print '%s already exist!'%sys.argv[1]
    sys.exit()

file=open(sys.argv[1],'w')
today=datetime.date.today()
date=today.strftime('%Y')+'-'+today.strftime('%m')+'-'+today.strftime('%d')
filetypes=string.split(sys.argv[1],'.')
length=len(filetypes)
filetype=filetypes[length-1]
if filetype=='py':
    print 'use python mode'
    file.writelines('# _*_ coding=utf-8 _*_')
    file.write('\n')
    file.writelines('#File: '+sys.argv[1])
    file.write('\n')
    file.write(py)
    file.write('# Date: '+date)
    file.write('\n')
    file.write('#------------------------------------------------')
elif filetype=='c' or filetype=='cpp':
    print 'use c mode'
    file.writelines('/*')
    file.write('\n')
    file.writelines('*--------------------------------------------------')
    file.write('\n')
    file.writelines('*File: '+sys.argc[1])
    file.write('\n')
    file.write(c)
    file.write('# Date: '+date)
    file.write('\n')
    file.write('*--------------------------------------------------')
    file.write('\n')
    file.write('*/ \n')

else:
    print 'just create %s' %sys.argv[1]

file.close()
                    
    
